package com.llc.mall.user.interfaces.app;

import com.llc.mall.user.application.command.service.UserAppService;
import com.llc.mall.user.application.command.commands.ModifyUserCmd;
import com.llc.mall.user.application.command.commands.UserRegisterCmd;
import com.llc.mall.user.application.query.service.UserQueryService;
import com.llc.mall.user.interfaces.vo.TokenVo;
import com.llc.mall.user.interfaces.vo.UserVo;
import com.llc.mall.common.core.response.ServerResponseEntity;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

@Tag(name = "用户")
@RequestMapping("/user")
@RestController
public class UserController {

    @Resource
    private UserAppService userAppService;

    @Resource
    private UserQueryService userQueryService;

    @Operation(summary = "用户注册")
    @PostMapping("/register")
    public ServerResponseEntity<TokenVo> register(@Valid @RequestBody UserRegisterCmd registerCmd) {
        TokenVo result = userAppService.register(registerCmd);
        return ServerResponseEntity.success(result);
    }

    @PostMapping ("/update_user")
    @Operation(summary = "更新用户信息")
    public ServerResponseEntity<Void> updateUser(@Valid @RequestBody ModifyUserCmd modifyUserCmd) {
        userAppService.modifyUser(modifyUserCmd);
        return ServerResponseEntity.success();
    }

    @GetMapping("/detail_info")
    @Operation(summary = "获取用户详细信息" , description = "返回用户详细信息")
    public ServerResponseEntity<UserVo> getUserDetailInfo() {
        UserVo userVo = userQueryService.detail();
        return ServerResponseEntity.success(userVo);
    }

}
